package com.iteaj.iboot.module.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iteaj.framework.BaseServiceImpl;
import com.iteaj.framework.result.ListResult;
import com.iteaj.iboot.module.iot.entity.ModelApiConfig;
import com.iteaj.iboot.module.iot.mapper.ModelApiConfigMapper;
import com.iteaj.iboot.module.iot.service.IModelApiConfigService;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 物模型接口配置 服务实现类
 * </p>
 *
 * @author iteaj
 * @since 2023-09-12
 */
@Service
public class ModelApiConfigServiceImpl extends BaseServiceImpl<ModelApiConfigMapper, ModelApiConfig>
    implements IModelApiConfigService
{
    @Override
    public Map<String, Object> getConfigByCode(String code)
    {
        ListResult<ModelApiConfig> list = this.list(new QueryWrapper<ModelApiConfig>().eq("api_code", code));
        Map<String, Object> map = list.stream().collect(
            Collectors.toMap(ModelApiConfig::getProtocolAttrField, ModelApiConfig::getValue));
        return map;
    }
}
